package com.ah.suams.dto;

import cn.hutool.crypto.digest.DigestUtil;
import com.ah.suams.bean.Admin;

public class LoginToken {

    private String ip;

    private String userAgent;

    private String now;

    private Admin admin;

    private static final String SALT = "!@#123";

    public String getToken(){
        StringBuilder builder = new StringBuilder();

        builder.append(ip);
        builder.append(userAgent);
        builder.append(now);
        builder.append(admin.getId());
        builder.append(SALT);

        String token = DigestUtil.md5Hex(builder.toString());

        return token;
    }

    public LoginToken() { }

    public LoginToken(String ip, String userAgent, String now, Admin admin) {
        this.ip = ip;
        this.userAgent = userAgent;
        this.now = now;
        this.admin = admin;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getNow() {
        return now;
    }

    public void setNow(String now) {
        this.now = now;
    }

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public static String getSALT() {
        return SALT;
    }

    @Override
    public String toString() {
        return "LoginToken{" +
                "ip='" + ip + '\'' +
                ", userAgent='" + userAgent + '\'' +
                ", now='" + now + '\'' +
                ", admin=" + admin +
                '}';
    }
}
